package com.hua.yuan.base;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

/**
 * 业务相关基类
 */

public abstract class BaseAppActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(initLayoutId());
        initView();
        initNet();
    }

    /**
     * 设置layout资源
     *
     * @return
     */
    protected abstract int initLayoutId();

    /**
     * 初始化视图控件
     *
     * @return
     */
    protected abstract void initView();

    /**
     * 初始化网络操作
     *
     * @return
     */
    protected abstract void initNet();


    /**
     * 通过Id得到view的实例
     *
     * @param viewId
     * @param <T>
     * @return
     */
    protected <T> T findView(int viewId) {
        return (T) findViewById(viewId);
    }

    @Override
    public void startActivity(final Intent intent) {
        if(getPackageManager().resolveActivity(intent,PackageManager.MATCH_DEFAULT_ONLY) != null) {

            super.startActivity(intent);
        }
    }
}
